<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateRoleTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('role', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '角色表']);
        $table
            ->addColumn(Column::string('name', 50)->setComment('角色名称'))
            ->addColumn(Column::string('description', 255)->setComment('角色描述'))
            ->addColumn(Column::integer('status', false)->setDefault(1)->setComment('状态 0:禁用 1:正常'))
            ->addColumn(Column::integer('create_time')->setComment('创建时间'))
            ->addColumn(Column::integer('update_time')->setComment('更新时间'))
            ->addColumn(Column::integer('delete_time')->setDefault(null)->setComment('删除时间'))
            ->addColumn(Column::tinyInteger('is_delete')->setDefault(0)->setComment('是否删除 1 => 是 0 => 否'))
            ->create();
    }
}
